package com.aftersale.demo.controller;

import com.aftersale.demo.pojo.AdminUser;
import com.aftersale.demo.Utils.Result;
import com.aftersale.demo.service.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController//标注返回json或数据
public class AdminController {

    @Autowired
    AdminUserService adminUserService;
    @PostMapping(value = "login")
    public Result login(@RequestBody AdminUser aduser){
        if(aduser.getUsername().isEmpty()||aduser.getPassword().isEmpty()){
            return Result.error("用户名或密码不能为空");
        }else{
            Integer i=adminUserService.login(aduser.getUsername(), aduser.getPassword());
            if(i==null){
                return Result.error("用户名不存在");
            }else{
                return Result.success(i);
            }
        }

    }
    @PostMapping(value = "register")
    public Result register(@RequestBody AdminUser aduser){
        if(aduser.getUsername().isEmpty()||aduser.getPassword().isEmpty()){
            return Result.error("用户名或密码不能为空");
        }
        else {
            adminUserService.register(aduser.getUsername(), aduser.getPassword());
            return Result.success(aduser);
        }
    }



}